<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jsps/tag.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>系统数据字典</title>
<%@ include file="/WEB-INF/jsps/common_css.jsp"%>
<%@ include file="/WEB-INF/jsps/common_js.jsp"%>

<script type="text/javascript">

$(function(){
	
	$('#baijia_list_id').datagrid({    
	    url:'${baseurl}baijia/list',
	    toolbar:"#baijia_toolbar_id"
	});
	
	
	//发布本地
	$("#baijia_add_id").click(function(){
        window.open("${baseurl}baijia/publishLocalUI","_blank");
        //TODO 弹窗提醒刷新 (借鉴三方支付效果)
    });

    //网络热文抓取
    $("#baijia_add_from_network").click(function(){
        window.open("${baseurl}baijia/networkFetchUI","_blank");
        //TODO 弹窗提醒刷新 (借鉴三方支付效果)baijia_add_from_network
    });
	
	//取消
	$("#baijia_edit_dialog_buttons_cancel_id").click(function(){
		$("#baijia_edit_id").dialog("close");
		$('#baijia_form_id').form("clear");
	});
	

 	//提交表单
	$("#baijia_edit_dialog_buttons_ok_id").click(function(){
		if(!$('#baijia_form_id').form("validate")){
			return;
		}
		
		var id = $("#id").val();
		var name = $("#baijia_name_id").val();
		var sn = $("#baijia_sn_id").val();
		
		$.post("${baseurl}baijia/saveOrUpdate", { "id":id,"name":name,"sn":sn},
			 function(data){
			  if(data.success){
		        	$('#baijia_list_id').datagrid("reload");
		        	$('#baijia_form_id').form("clear");
		        	$.messager.show({title:'系统提示',msg:data.content,timeout:5000,showType:'slide'});
		        }
			    $("#baijia_edit_id").dialog("close");
			    $('#baijia_form_id').form("clear");
			    $.messager.show({title:'操作失败',msg:data.content,timeout:5000,showType:'slide'});
			  }
			 ,"json"); 
	});
	
	
	//删除
	$("#baijia_delete_id").click(function(){
		var selected =  $("#baijia_list_id").datagrid("getSelected");
		if(selected == null){
			alert("请选中你要删除的记录.");
		}else{
			$.post("${baseurl}baijia/delete", { "id":selected.id},
					   function(data){
					    	if(data.success){
					    		$('#baijia_list_id').datagrid("reload");
					    		$.messager.show({title:'系统提示',msg:data.content,timeout:5000,showType:'slide'});
					    	}else{
					    		$('#baijia_form_id').form("clear");
					    		$.messager.alert('警告',data.content); 
					    	}
					   }, "json");
		}
	});
	

	//修改
	$("#baijia_update_id").click(function(){
		var selected =  $("#baijia_list_id").datagrid("getSelected");
		if(selected == null){
			alert("请选中你要修改的记录.");
		}else{
			$('#baijia_form_id').form("load",selected);
			//设置字典类型编号不可以编辑(字典类型编号不可以修改)
			$('#baijia_sn_id').attr('readonly',true);
			$("#baijia_edit_id").dialog("open");
		}
	});


	
});
	
</script>
</head>
<body>
	<table id="baijia_list_id" style="width:100%;height:100%;"
		data-options="fitColumns:true,singleSelect:true,pagination:true,pagePosition:'bottom'">   
	    <thead>   
	        <tr>   
	            <th data-options="field:'title',width:20">id</th>
	            <th data-options="field:'content',width:20">标题</th>
              	<th data-options="field:'origin_url',width:20">原文地址</th>
              	<th data-options="field:'cover_images',width:20">封面图片</th>
              	<th data-options="field:'is_original',width:20">是否原创</th>
              	<th data-options="field:'status',width:20">状态</th>
	        </tr>
	    </thead>   
	</table>
	
	<!-- 数据表格toolbar -->
	<div id="baijia_toolbar_id">
		<a id="baijia_add_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">手动本地发布</a>
		<a id="baijia_add_from_network" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">网络热文采摘</a>
		<a id="baijia_update_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>
		<a id="baijia_delete_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
	</div>
	
	<!-- 编辑对话框 -->
	<div id="baijia_edit_id" class="easyui-dialog" title="字典管理" style="width:300px;height:150px"   
        data-options="iconCls:'icon-save',modal:true,closed:true,buttons:'#baijia_edit_dialog_buttons_id'">   
   		<form id="baijia_form_id" method="post">
   			<input id="id" type="hidden" name="id"/>
   			<table>
   				<tr>
   					<td>
   						<div>   
					        <label for="baijianame">类型名称:</label>   
					        <input id="baijia_name_id" class="easyui-validatebox" type="text" name="name" data-options="required:true" />
					    </div> 
   					</td>
   				</tr>
   				<tr>
   					<td>
   						<div>   
					        <label for="baijianame">类型编号:</label>
					        <input id="baijia_sn_id" class="easyui-validatebox" type="text" name="sn" data-options="required:true" />   
					    </div> 
   					</td>
   				</tr>
   			</table>
		</form>
	</div>
	
	<!-- 编辑对话框的buttons -->
	<div id="baijia_edit_dialog_buttons_id">
		<a id="baijia_edit_dialog_buttons_ok_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">保存</a>
		<a id="baijia_edit_dialog_buttons_cancel_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">关闭</a>
	</div>
	
</body>
</html>